class Point:
    def __init__(self, x, y):
        self.x = float(x)
        self.y = float(y)

    def __init__(self, list):
        try:
            self.x = float(list[0])
            self.y = float(list[1])
        except:
            self.x = list.x
            self.y = list.y
            pass

    def subtract(self, p):
        return Point([self.x - p.x, self.y - p.y])

    def __str__(self):
        return '(' + str(self.x) + ', ' + str(self.y) + ')'
    
    def mul(self, x):
        return Point([self.x *x, self.y *x])

# calculates the cross product of vector p1 and p2
# if p1 is clockwise from p2 wrt origin then it returns +ve value
# if p2 is anti-clockwise from p2 wrt origin then it returns -ve value
# if p1 p2 and origin are collinear then it returs 0
def cross_product(p1, p2):
	return p1.x * p2.y - p2.x * p1.y

# returns the cross product of vector p1p3 and p1p2
# if p1p3 is clockwise from p1p2 it returns +ve value
# if p1p3 is anti-clockwise from p1p2 it returns -ve value
# if p1 p2 and p3 are collinear it returns 0
def direction(p1, p2, p3):
	return  cross_product(p3.subtract(p1), p2.subtract(p1))


# checks if line segment p1p2 and p3p4 intersect
def intersect(p1, p2, p3, p4):
    p1 = Point(p1)
    p2 = Point(p2)
    p3 = Point(p3)
    p4 = Point(p4)
    d1 = direction(p3, p4, p1)
    d2 = direction(p3, p4, p2)
    d3 = direction(p1, p2, p3)
    d4 = direction(p1, p2, p4)

    if ((d1 > 0 and d2 < 0) or (d1 < 0 and d2 > 0)) and \
        ((d3 > 0 and d4 < 0) or (d3 < 0 and d4 > 0)):
        return True


    return False
